//
// isr.c -- High level interrupt sevice routines and inerrupt request handlers
// Part of this code is modified from Bran's kernel development tutorials
// Rewritten for JamesM's kernel development tutorials
//

#include <common.h>
#include <isr.h>
#include <monitor.h>

isr_t interrupt_handlers[256];

//This gets called from our ASM interrupt handler stub.
void isr_handler (registers_t regs)
{
//	monitor_write("received interrupt: ");
//	monitor_write_dec(regs.int_no);
//	monitor_put('\n');
}

void irq_handler (registers_t regs)
{
	//Sends an EOI signal to the PICs
	//If this inerrupt invovled the slave
	if (regs.int_no >= 40)
	{
		//send reset signal to slave.
		outb(0xA0, 0x20);
	}
	
	//send reset signal to master, as well as slave, if necessary
	outb(0x20, 0x20);
	
	if (interrupt_handlers[regs.int_no] != 0)
	{
		isr_t handler = interrupt_handlers[regs.int_no];
		handler(regs);
	}
}

void register_interrupt_handler(u8int n, isr_t handler)
{
	interrupt_handlers[n] = handler;
}

void unregister_interrupt_handler(u8int n)
{
    interrupt_handlers[n] = 0;
}
